

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


/*
 @Sangeeta
 @Uses: Program to add fname field in the svn_info as currently it does not have it.
 */

public class a_add_fname_svn_info 
{
 
  public  String user="root";
  public  String passwd="123";
  public  String dbname="2apache";
  public Connection conn=null;


public void process(Connection conn)
{

  Statement stmt =  null;
  String select="select * from a_svn_info"; 
  try
   {
	    stmt =  conn.createStatement();
	    stmt.execute(select);
	    ResultSet rs = stmt.getResultSet();
	    
	    while(rs.next())
	    {
	    	String svnid =  rs.getString("svnid");
	    	int file_no = rs.getInt("file_no");
	    	String file_changed = rs.getString("file_changed");
	    	String fname =  getFileName(file_changed);
	    	insert_to_db(svnid,file_no,fname,conn);
	    }
	           
	    if(stmt!=null)
	    {
	    	stmt.close();
	    }
   } catch (SQLException e) 
   {e.printStackTrace(); } 
  

}//process 
  
private void insert_to_db(String svnid, int file_no, String fname,Connection conn) 
{

	Statement stmt = null;
	String insert="update a_svn_info set fname='"+fname+"' where svnid='"+svnid+"' and file_no='"+file_no+"'";
	System.out.println("insert="+insert);
	try
	{
		stmt = conn.createStatement();
		stmt.executeUpdate(insert);
	} catch (SQLException e)
	{ 	e.printStackTrace(); 	}
}//insert

private String getFileName(String file_changed) 
{
  String fname = "";
  int index=file_changed.lastIndexOf("/");
  fname=file_changed.substring(index+1).trim();

  return fname ;
}

public void intr()
{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));	
   System.out.println("INTR");
   try {
	br.readLine();
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
}

//main 
public static void main(String args[])
  {
	   a_add_fname_svn_info af =  new a_add_fname_svn_info();
	   
	   db_conn db =  new db_conn();
	   af.conn=db.connect(af.dbname, af.user, af.passwd);
	   af.process(af.conn);
	   db.close(af.conn);
  }//main

}//
